package com.scedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scedu.entity.Permission;
import com.scedu.entity.User;
import com.scedu.mapper.UserDao;
import com.scedu.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sc
 * @since 2020-04-21
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    @Autowired
    private  UserDao userDao;
    @Override
    public User findByUserName(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return userDao.selectOne(wrapper);
    }

    @Override
    public List<String> findPermissionByUid(String uid) {
        List<Permission> permissionList=userDao.findPermissionByUid(uid);
        List<String> permissions=new ArrayList<>();
        permissionList.forEach(obj -> permissions.add(obj.getPermissionName()));
        return permissions;
    }
}
